//
//  commentJokeTableViewCell.m
//  HaHa
//
//  Created by 姚君泽 on 15/9/23.
//  Copyright (c) 2015年 吉亚平. All rights reserved.
//

#import "commentJokeTableViewCell.h"

@implementation commentJokeTableViewCell
//model赋值
-(void)setValueWithModel:(CommentsModel *)model
{
    [self.commenterImageView sd_setImageWithURL:[NSURL URLWithString:model.avatar_url]];
    self.commenterLabel.text = model.user_name;
    self.timerLabel.text = [self Retrun:model.create_time];
    self.commentLabel.text = model.text;
    [self setCellFrame];
}
- (NSString *)Retrun:(NSString *)str{
    NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
    
    formatter.timeZone = [NSTimeZone timeZoneWithName:@"shanghai"];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"MM-dd HH:mm"];
    NSDate* date = [NSDate dateWithTimeIntervalSince1970:[str doubleValue]];
    NSString* dateString = [formatter stringFromDate:date];
    return dateString;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.commenterImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 20, 40, 40)];
        self.commenterImageView.layer.masksToBounds = YES;
        self.commenterImageView.layer.cornerRadius = self.commenterImageView.frame.size.height / 2;
        
        [self addSubview:self.commenterImageView];
        
        self.commenterLabel = [[UILabel alloc] initWithFrame:CGRectMake(60, 10, 170, 40)];
        self.commenterLabel.textColor = [UIColor grayColor];
        
        [self addSubview:self.commenterLabel];
        
        self.timerLabel = [[UILabel alloc] initWithFrame:CGRectMake(280, 10, 170, 40)];
        self.timerLabel.font = [UIFont boldSystemFontOfSize:11];
        self.timerLabel.textColor = [UIColor grayColor];
        
        [self addSubview:self.timerLabel];
        
        self.commentLabel = [[UILabel alloc] initWithFrame:CGRectMake(60, 50, kScreenWdth - 90, 300)];
        
        
        [self addSubview:self.commentLabel];
        
        
    }
    return self;
}
-(void)setCellFrame
{
    self.commentLabel.numberOfLines = 0;
    self.commentLabel.lineBreakMode = NSLineBreakByCharWrapping;
    CGSize size = [self.commentLabel sizeThatFits:CGSizeMake(self.commentLabel.frame.size.width,MAXFLOAT)];
    self.commentLabel.frame = CGRectMake(self.commentLabel.frame.origin.x, self.commentLabel.frame.origin.y, self.commentLabel.frame.size.width, size.height);
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
